#pragma once
#include <string>
#include "InetAddr.hpp"
#include "log.hpp"
#include <list>
#include "ThreadPool.hpp"
#include "mutex.hpp"
#include <memory>

using namespace LogModule;

class UserInterface
{
public:
    virtual ~UserInterface() = default;                              // 为了防止调用接口时，调用到UserInterface的析构函数，导致析构函数调用不明确
    virtual void Sendto(int sockfd, const std::string &message) = 0; // 纯虚函数必须要求子类对纯虚函数进行重定义实现
    virtual std::string GetId() = 0;                                 // 获取用户的ID
    virtual bool operator==(const InetAddr &u) = 0;
};

class User : public UserInterface // public继承
{
public:
    User(InetAddr &id) : _adr(id)
    {
    }
    bool operator==(const InetAddr &id) override
    {
        return _adr == id; // 使用InetAddr的重载==运算符
    }
    void Sendto(int sockfd, const std::string &message) override
    {
        LOG(LogLevel::DEBUG) << "sendto message to:  " << _adr.Addr();
        ::sendto(sockfd, message.c_str(), message.size(), 0, _adr.Getsockaddr(), _adr.GetSockaddrLen());
    }
    std::string GetId() override
    {
        return _adr.GetIp() + ":" + std::to_string(_adr.GetPort());
    }
    ~User()
    {
    }

private:
    InetAddr _adr; // 用户的地址
};

